package com.uottawa.librarytest.dao;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.uottawa.library.dao.BaseDAO;
import com.uottawa.library.dao.UserDAO;
import com.uottawa.library.domain.User;

public class UserDAOTest {

	private UserDAO dao;
	
	/**
	 * Execute this method before every test to reset and initialize the test data.
	 */
	@Before
	public void setUp() {
		dao = new UserDAO();
	}
	
	@After
	public void cleanUp() {
		new BaseDAO().cleanUp();
	}
	
	@Test
	public void testAddNewUserNotExist(){
		User u = new User(11111, "OkUser", "password", 0, "user");
		boolean added = dao.addUser(u);
		
		assertTrue(added);
	}
	
	@Test
	public void testAddDuplicateUser(){
		User u = new User(222222, "OkUser", "password", 0, "user");
		
		dao.addUser(u);
		boolean added = dao.addUser(u);
		assertFalse(added);
	}
	
	@Test 
	public void removeUser(){
		User u = new User(333333, "OkUser", "password", 0, "user");

		dao.addUser(u);
		boolean removed = dao.removeUser(u);
		assertTrue(removed);
	}

}
